﻿<?php
	$this->title = 'Listes des demandes';
	$this->headTitle($this->title);
?>
	<h3>Vos demandes</h3>
	<table id='listedemandes'>
		<thead>
			<tr>
				<th>ID</th>
				<th>Type de demande</th>
				<th>Date de demande</th>
				<th>Etat</th>
				<th>Demandeur</th>
				<th>Voir</th>
			</tr>
		</thead>
		<tbody>
			<?php foreach($this->demandes as $demande) : 
			if(!isset($this->id) || (isset($this->id) && $this->id == $demande->Id_utilisateur))
				{
				$type = $this->escape($demande->Type);
			?>
			<tr>
				<td><?php echo $this->escape($demande->Id_demande);?></td>
				<td><?php echo $this->escape($demande->Type);?></td>
				<td><?php $date = explode(" ",$this->escape($demande->Date_demande)); 
					      echo $date[0];?></td>
				<td><?php $etat = $this->escape($demande->Etat);
						  if($etat == 0){
						  	echo "<span style='color:red' >En attente</span>";
						  }elseif ($etat == 1){
						  	echo "<span style='color:orange' >En cours</span>";
						  }else {
						  	echo "<span style='color:green' >Traité</span>";
						  }
				?></td>
				<td><?php $utilisateur = new Application_Model_DbTable_Utilisateur();
						  if($utilisateur->exist($demande->Id_utilisateur)){?><a href="<?php echo $this->url(array('controller'=>'Profil','action'=>'afficher-profil', 'id'=>$demande->Id_utilisateur));?>">Voir</a><?php }?></td>
				<td><?php if($type == "demande affiliation")
							{
								echo "<a href='".$this->url(array('controller'=>'AfficherLesDemandes','action'=>'demande-affiliation', 'id'=>$demande->Id_demande))."'>Voir</a>";
							}
						  if($type == "demande reversion")
							{
								echo "<a href='".$this->url(array('controller'=>'AfficherLesDemandes','action'=>'demande-reversion', 'id'=>$demande->Id_demande))."'>Voir</a>";
							}
						  else if($type == "demande informations")
							{
								echo "<a href='".$this->url(array('controller'=>'AfficherLesDemandes','action'=>'demande-informations', 'id'=>$demande->Id_demande))."'>Voir</a>";
							}
						 else if($type == "demande modification")
							{
								echo "<a href='".$this->url(array('controller'=>'AfficherLesDemandes','action'=>'demande-modification-dossier', 'id'=>$demande->Id_demande))."'>Voir</a>";
							}
					?></td>
			</tr>
			<?php 
			}
			endforeach; ?>
		</tbody>
	</table>
<br />	


<script type="text/javascript"> 
	$(function () {
		tableToGrid("#listedemandes", {height:"auto", width:"650", caption: "Liste des demandes"});
		$("#listedemandes").jqGrid('gridResize',{minWidth:300,maxWidth:600,minHeight:100, maxHeight:800});
	});
</script>